package org.pearl.matedemo;

import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.binding.MapperMethod;
import org.apache.ibatis.io.ResolverUtil;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by TD on 2021/11/2
 */
public class MapperScanTest {

    // 存放数据权限
    private static ConcurrentHashMap<String, String> cache = new ConcurrentHashMap<>();

    public static void main(String[] args) {
        ResolverUtil<Class<?>> resolverUtil = new ResolverUtil();
        System.out.println("==================================");
        resolverUtil.find(new ResolverUtil.IsA(Object.class), "mybatis.mate.O00000o");
        // 获取当前包下所有类
        Set<Class<? extends Class<?>>> mapperSet = resolverUtil.getClasses();
        Iterator var5 = mapperSet.iterator();
        while (var5.hasNext()) {
            Class<?> mapperClass = (Class) var5.next();
            // 获取所有方法
            System.out.println(mapperClass.getName());
            Method[] methods = mapperClass.getMethods();
            for (Method method : methods) {

            }
        }

    }

    private static boolean canHaveStatement(Method method) {
        return !method.isBridge() && !method.isDefault();
    }

    private static String generateResultMapName(Method method, Class<?> type) {
        Results results = (Results) method.getAnnotation(Results.class);
        if (results != null && !results.id().isEmpty()) {
            return type.getName() + "." + results.id();
        } else {
            StringBuilder suffix = new StringBuilder();
            Class[] var4 = method.getParameterTypes();
            int var5 = var4.length;

            for (int var6 = 0; var6 < var5; ++var6) {
                Class<?> c = var4[var6];
                suffix.append("-");
                suffix.append(c.getSimpleName());
            }

            if (suffix.length() < 1) {
                suffix.append("-void");
            }

            return type.getName() + "." + method.getName() + suffix;
        }
    }


    private static Class<?> getParameterType(Method method) {
        Class<?> parameterType = null;
        Class<?>[] parameterTypes = method.getParameterTypes();
        Class[] var4 = parameterTypes;
        int var5 = parameterTypes.length;

        for (int var6 = 0; var6 < var5; ++var6) {
            Class<?> currentParameterType = var4[var6];
            if (!RowBounds.class.isAssignableFrom(currentParameterType) && !ResultHandler.class.isAssignableFrom(currentParameterType)) {
                if (parameterType == null) {
                    parameterType = currentParameterType;
                } else {
                    parameterType = MapperMethod.ParamMap.class;
                }
            }
        }

        return parameterType;
    }


}
